// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Serverless.Fluent;
using Elastic.Clients.Elasticsearch.Serverless.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.Serverless.IndexManagement;

public sealed partial class IndexingSlowlogSettings
{
	[JsonInclude, JsonPropertyName("level")]
	public string? Level { get; set; }
	[JsonInclude, JsonPropertyName("reformat")]
	public bool? Reformat { get; set; }
	[JsonInclude, JsonPropertyName("source")]
	public int? Source { get; set; }
	[JsonInclude, JsonPropertyName("threshold")]
	public Elastic.Clients.Elasticsearch.Serverless.IndexManagement.IndexingSlowlogTresholds? Threshold { get; set; }
}

public sealed partial class IndexingSlowlogSettingsDescriptor : SerializableDescriptor<IndexingSlowlogSettingsDescriptor>
{
	internal IndexingSlowlogSettingsDescriptor(Action<IndexingSlowlogSettingsDescriptor> configure) => configure.Invoke(this);

	public IndexingSlowlogSettingsDescriptor() : base()
	{
	}

	private string? LevelValue { get; set; }
	private bool? ReformatValue { get; set; }
	private int? SourceValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.IndexManagement.IndexingSlowlogTresholds? ThresholdValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.IndexManagement.IndexingSlowlogTresholdsDescriptor ThresholdDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.IndexManagement.IndexingSlowlogTresholdsDescriptor> ThresholdDescriptorAction { get; set; }

	public IndexingSlowlogSettingsDescriptor Level(string? level)
	{
		LevelValue = level;
		return Self;
	}

	public IndexingSlowlogSettingsDescriptor Reformat(bool? reformat = true)
	{
		ReformatValue = reformat;
		return Self;
	}

	public IndexingSlowlogSettingsDescriptor Source(int? source)
	{
		SourceValue = source;
		return Self;
	}

	public IndexingSlowlogSettingsDescriptor Threshold(Elastic.Clients.Elasticsearch.Serverless.IndexManagement.IndexingSlowlogTresholds? threshold)
	{
		ThresholdDescriptor = null;
		ThresholdDescriptorAction = null;
		ThresholdValue = threshold;
		return Self;
	}

	public IndexingSlowlogSettingsDescriptor Threshold(Elastic.Clients.Elasticsearch.Serverless.IndexManagement.IndexingSlowlogTresholdsDescriptor descriptor)
	{
		ThresholdValue = null;
		ThresholdDescriptorAction = null;
		ThresholdDescriptor = descriptor;
		return Self;
	}

	public IndexingSlowlogSettingsDescriptor Threshold(Action<Elastic.Clients.Elasticsearch.Serverless.IndexManagement.IndexingSlowlogTresholdsDescriptor> configure)
	{
		ThresholdValue = null;
		ThresholdDescriptor = null;
		ThresholdDescriptorAction = configure;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (!string.IsNullOrEmpty(LevelValue))
		{
			writer.WritePropertyName("level");
			writer.WriteStringValue(LevelValue);
		}

		if (ReformatValue.HasValue)
		{
			writer.WritePropertyName("reformat");
			writer.WriteBooleanValue(ReformatValue.Value);
		}

		if (SourceValue.HasValue)
		{
			writer.WritePropertyName("source");
			writer.WriteNumberValue(SourceValue.Value);
		}

		if (ThresholdDescriptor is not null)
		{
			writer.WritePropertyName("threshold");
			JsonSerializer.Serialize(writer, ThresholdDescriptor, options);
		}
		else if (ThresholdDescriptorAction is not null)
		{
			writer.WritePropertyName("threshold");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.IndexManagement.IndexingSlowlogTresholdsDescriptor(ThresholdDescriptorAction), options);
		}
		else if (ThresholdValue is not null)
		{
			writer.WritePropertyName("threshold");
			JsonSerializer.Serialize(writer, ThresholdValue, options);
		}

		writer.WriteEndObject();
	}
}